package cn.kooki.app.duobao.ui.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.kooki.app.duobao.R;


/**
 * Created by xiong on 2015/12/13.
 */
public class BankPicker extends FrameLayout {


    @Bind(R.id.iv_bank_weixin_logo)
    ImageView ivBankWeixinLogo;
    @Bind(R.id.iv_bank_weixin_title)
    TextView ivBankWeixinTitle;
    @Bind(R.id.iv_bank_weixin_tag)
    ImageView ivBankWeixinTag;
    @Bind(R.id.iv_bank_weixin_detail)
    TextView ivBankWeixinDetail;

    @Bind(R.id.weixinBank1)
    RelativeLayout weixinBank1;
    @Bind(R.id.iv_bank_aibei_logo)
    ImageView ivBankAibeiLogo;
    @Bind(R.id.iv_bank_aibei_title)
    TextView ivBankAibeiTitle;
    @Bind(R.id.iv_bank_aibei_tag)
    ImageView ivBankAibeiTag;
    @Bind(R.id.iv_bank_aibei_detail)
    TextView ivBankAibeiDetail;

    @Bind(R.id.aibeiBank)
    RelativeLayout aibeiBank;

    @Bind(R.id.rb_wx)
    ImageView rbWx;
    @Bind(R.id.rb_ab)
    ImageView rbAb;
    @Bind(R.id.picker_loading)
    ProgressBar pickerLoading;
    @Bind(R.id.picker_content)
    LinearLayout pickerContent;
    @Bind(R.id.radioGroup)
    RelativeLayout radioGroup;

    private int checkedId = -1;

    public int getCheckedId() {
        return checkedId;
    }

    public static final int WEIXIN_TYPE = 3;

    public static final int AIBEI_TYPE = 4;

    private int type = -1;

    public int getSelectType() {
        return type;
    }

    public BankPicker(Context context) {
        this(context, null);
    }

    public BankPicker(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BankPicker(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public BankPicker(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.layout_banks_new, this, true);
        ButterKnife.bind(this);

    }

    @OnClick({R.id.weixinBank1, R.id.aibeiBank})
    public void onSelectBank(View view) {
        weixinBank1.setSelected(false);
        aibeiBank.setSelected(false);
        view.setSelected(true);
        if (view == weixinBank1) {
            type = WEIXIN_TYPE;
        } else {
            type = AIBEI_TYPE;
        }
    }

    public void hideProgress() {
        pickerContent.setVisibility(VISIBLE);
        pickerLoading.setVisibility(GONE);
    }

    public void hideProgress(int type) {
        weixinBank1.setVisibility(VISIBLE);
        aibeiBank.setVisibility(VISIBLE);
        if (type == WEIXIN_TYPE) {
            weixinBank1.setVisibility(GONE);
        } else if (type == AIBEI_TYPE) {
            aibeiBank.setVisibility(GONE);
        }
        hideProgress();
    }

}
